'use strict';

const Controller = require('egg').Controller;
const { getCookieValue } = require('../public/processCookies');
/**
* @controller Tr069CommandController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class Tr069CommandController extends Controller {
  async list() {
    /**
        * @summary tr069commandlist
        * @description tr069commandlist
        * @router get /tr069commandlist
        * @request query integer limit
        * @request query integer page
        * @request query string deviceType
        * @request query string typeName
        */
    const params = this.ctx.query;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.tr069Command.list(params);
    this.ctx.body = {
      msg: '',
      status: 200,
      data: result.rows,
      count: result.count,
    };
  }

  async create() {
    /**
        * @summary tr069commandcreate
        * @description tr069commandcreate
        * @router post /tr069commandcreate
        * @request body tr069command
        */
    const params = this.ctx.request.body;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.tr069Command.create(params);
    global.log.desc = `${params.deviceType} ${params.templateName} create tr069Command `;
    this.ctx.body = {
      msg: result.msg,
    };
  }

  async update() {
    /**
        * @summary tr069commandupdate
        * @description tr069commandupdate
        * @router post /tr069commandupdate
        * @request body tr069command
        */
    const params = this.ctx.request.body;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.tr069Command.update(params);
    this.ctx.body = {
      data: result.msg,
    };
  }

  async delete() {
    /**
        * @summary tr069commanddelete
        * @description tr069commanddelete
        * @router post /tr069commanddelete
        * @request body tr069command
        */
    const params = this.ctx.request.body;
    const result = await this.ctx.service.tr069Command.delete(params);
    this.ctx.body = {
      data: result.msg,
    };
  }
}
module.exports = Tr069CommandController;
